/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

/**
 *
 * @author Dickson
 */
import java.io.*;

public class CopyFile {

    private static void copyfile(String srFile, String dtFile) {
        try {
            File sourceFile = new File(srFile);
            File destFile = new File(dtFile);
            InputStream in = new FileInputStream(sourceFile);
            OutputStream out = new FileOutputStream(destFile);

            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
            System.out.println("File copied.");
        } catch (FileNotFoundException ex) {
            System.out.println(ex.getMessage() + " in the specified directory.");
            System.exit(0);
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }

    private static void createDirectory(String dtFile) {
        File destFile = new File(dtFile);
        if (destFile.exists() == false) {
            destFile.mkdirs();
        }
    }

    public static void main(String[] args) {
        String[] sourceFiles = {"Calendar.data.db", "Calendar.index.db", "Calendar.trace.db"};
        String destination = System.getProperty("user.home") + "/nageIT/";
        createDirectory(destination);
        for (String source : sourceFiles) {
            copyfile("C:/nageIT/DB/" + source, destination + source);
        }

//        File destFile = new File("C:/nageIT/DB/Calendar.trace.db");
//        System.out.println("== " + destFile.exists());
    }
}
